package backgammon;

/**
 * <p>The dice that are used to determine how many positions to move.</p>
 * @author Jacob Kwitkoski
 * @version 1.0
 */
public class Dice {
    /**
     * <p>The value of die 1.</p>
     */
    private int die1;

    /**
     * <p>The value of die 2.</p>
     */
    private int die2;

    private int die1uses;

    private int die2uses;

    private boolean doubles;

    public Dice() {
        die1uses = 0;
        die2uses = 0;
    }

    /**
     * <p>Returns the value of die 1.</p>
     * @return the value of die 1.
     */
    public final int getDie1() {
        return die1;
    }

    /**
     * <p>Returns the value of die 2.</p>
     * @return the value of die 2.
     */
    public final int getDie2() {
        return die2;
    }

    public boolean isDie1used() {
        boolean die1used = false;
        if (doubles) {
            if (die1uses == 2) {
                die1used = true;
            }
        } else {
            if (die1uses == 1) {
                die1used = true;
            }
        }
        return die1used;
    }

    public boolean isDie2used() {
        boolean die2used = false;
        if (doubles) {
            if (die2uses == 2) {
                die2used = true;
            }
        } else {
            if (die2uses == 1) {
                die2used = true;
            }
        }
        return die2used;
    }

    public void useDie1() {
        die1uses++;
    }
    public void useDie2() {
        die2uses++;
    }

    /**
     * <p>Rolls the dice; sets die1 and die2 with new values of 1-6.</p>
     */
    public final void roll() {
        die1 = (int) (Math.random() * 6) + 1;
        die2 = (int) (Math.random() * 6) + 1;

        //DOUBLES TESTING
        //die2 = die1;

        if (die1 == die2) {
            doubles = true;
        } else {
            doubles = false;
        }
        //die1used = false;
        //die2used = false;
        die1uses = 0;
        die2uses = 0;
    }

}
